package p270jp.pxv.android.activity;

import android.animation.ObjectAnimator;
import android.content.ComponentCallbacks;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableString;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import androidx.compose.p026ui.platform.C0536v1;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.emoji2.text.RunnableC0624k;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.appbar.MaterialToolbar;
import p014ae.AbstractActivityC0164u0;
import p018ai.PixivSettings;
import p047bg.C1124a;
import p064c6.Preconditions;
import p082co.CharcoalDialogButtonSettings;
import p082co.CharcoalDialogFragment;
import p162fl.WorkTypeRepository;
import p165fo.Subscribe;
import p189gn.AbstractC3435a;
import p216hn.Lambda;
import p216hn.Reflection;
import p270jp.pxv.android.R;
import p270jp.pxv.android.commonObjects.model.WorkType;
import p270jp.pxv.android.event.ConfirmLearningDialogEvent;
import p270jp.pxv.android.event.HomeRecyclerViewFirstScrolledEvent;
import p270jp.pxv.android.topLevel.presentation.TopLevelStore;
import p270jp.pxv.android.view.TutorialScrollNavigationView;
import p274k2.ContextCompat;
import p307l9.EdgeTreatment;
import p314lg.ActivityHomeBinding;
import p325m0.MutabilityOwnership;
import p370ni.StartUpScreen;
import p374nm.C5413s0;
import p374nm.ToolbarMenuView;
import p436q6.C5768b;
import p452qn.C5859m;
import p545uf.StringUtils;
import p551ul.TopLevelStoreExtension;
import p574vi.LikeSettings;
import p579vo.Qualifier;
import p603wm.AbstractC6949c;
import p625xi.LegacyNavigation;
import p639y6.C7296l;

/* compiled from: HomeActivity.kt */
/* renamed from: jp.pxv.android.activity.HomeActivity */
/* loaded from: classes2.dex */
public final class HomeActivity extends AbstractActivityC0164u0 {

    /* renamed from: q0 */
    public static final /* synthetic */ int f18358q0;

    /* renamed from: j0 */
    public final AbstractC6949c f18359j0 = Preconditions.m9802P(1, new C4008c(this, null, null));

    /* renamed from: k0 */
    public final AbstractC6949c f18360k0 = Preconditions.m9802P(1, new C4009d(this, null, null));

    /* renamed from: l0 */
    public final AbstractC6949c f18361l0 = Preconditions.m9802P(1, new C4010e(this, null, null));

    /* renamed from: m0 */
    public final AbstractC6949c f18362m0 = Preconditions.m9802P(1, new C4011f(this, null, null));

    /* renamed from: n0 */
    public ActivityHomeBinding f18363n0;

    /* renamed from: o0 */
    public boolean f18364o0;

    /* renamed from: p0 */
    public boolean f18365p0;

    /* compiled from: HomeActivity.kt */
    /* renamed from: jp.pxv.android.activity.HomeActivity$a */
    /* loaded from: classes2.dex */
    public static final class C4006a {
        /* renamed from: a */
        public static final Intent m4824a(Context context) {
            return new Intent(context, HomeActivity.class);
        }
    }

    /* compiled from: HomeActivity.kt */
    /* renamed from: jp.pxv.android.activity.HomeActivity$b */
    /* loaded from: classes2.dex */
    public /* synthetic */ class C4007b {

        /* renamed from: a */
        public static final /* synthetic */ int[] f18366a;

        static {
            int[] iArr = new int[WorkType.values().length];
            iArr[WorkType.MANGA.ordinal()] = 1;
            iArr[WorkType.NOVEL.ordinal()] = 2;
            f18366a = iArr;
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.activity.HomeActivity$c */
    /* loaded from: classes2.dex */
    public static final class C4008c extends Lambda implements AbstractC3435a<LikeSettings> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f18367a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4008c(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f18367a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [vi.a, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final LikeSettings invoke() {
            return C1124a.m10173s(this.f18367a).f24118a.m920a().m621a(Reflection.m5499a(LikeSettings.class), null, null);
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.activity.HomeActivity$d */
    /* loaded from: classes2.dex */
    public static final class C4009d extends Lambda implements AbstractC3435a<WorkTypeRepository> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f18368a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4009d(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f18368a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [fl.e, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final WorkTypeRepository invoke() {
            return C1124a.m10173s(this.f18368a).f24118a.m920a().m621a(Reflection.m5499a(WorkTypeRepository.class), null, null);
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.activity.HomeActivity$e */
    /* loaded from: classes2.dex */
    public static final class C4010e extends Lambda implements AbstractC3435a<PixivSettings> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f18369a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4010e(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f18369a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [ai.b, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final PixivSettings invoke() {
            return C1124a.m10173s(this.f18369a).f24118a.m920a().m621a(Reflection.m5499a(PixivSettings.class), null, null);
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.activity.HomeActivity$f */
    /* loaded from: classes2.dex */
    public static final class C4011f extends Lambda implements AbstractC3435a<LegacyNavigation> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f18370a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4011f(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f18370a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, xi.a] */
        @Override // p189gn.AbstractC3435a
        public final LegacyNavigation invoke() {
            return C1124a.m10173s(this.f18370a).f24118a.m920a().m621a(Reflection.m5499a(LegacyNavigation.class), null, null);
        }
    }

    /* renamed from: g1 */
    public final PixivSettings m4826g1() {
        return (PixivSettings) this.f18361l0.getValue();
    }

    /* renamed from: h1 */
    public final void m4825h1(CharSequence charSequence) {
        if (!this.f18365p0) {
            this.f18365p0 = true;
            ActivityHomeBinding jVar = this.f18363n0;
            if (jVar != null) {
                jVar.f21709v.setText(charSequence);
                ActivityHomeBinding jVar2 = this.f18363n0;
                if (jVar2 != null) {
                    jVar2.f21709v.setVisibility(0);
                    ActivityHomeBinding jVar3 = this.f18363n0;
                    if (jVar3 != null) {
                        jVar3.f21710w.setVisibility(0);
                        ActivityHomeBinding jVar4 = this.f18363n0;
                        if (jVar4 != null) {
                            TutorialScrollNavigationView tutorialScrollNavigationView = jVar4.f21709v;
                            tutorialScrollNavigationView.f19702a.f22513q.getViewTreeObserver().addOnGlobalLayoutListener(new p374nm.TutorialScrollNavigationView(tutorialScrollNavigationView));
                            return;
                        }
                        MutabilityOwnership.m3737u("binding");
                        throw null;
                    }
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
    }

    @Override // p014ae.TopLevelActivity, p270jp.pxv.android.activity.AbstractActivityC4151b, p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        ViewDataBinding d = DataBindingUtil.m11369d(this, R.layout.activity_home);
        MutabilityOwnership.m3746l(d, "setContentView(this, R.layout.activity_home)");
        ActivityHomeBinding jVar = (ActivityHomeBinding) d;
        this.f18363n0 = jVar;
        MaterialToolbar materialToolbar = jVar.f21708u;
        MutabilityOwnership.m3746l(materialToolbar, "binding.toolBar");
        C0536v1.m11537h(this, materialToolbar, R.string.home);
        m11131K0().m11251d0("fragment_request_key_charcoal_dialog_fragment", this, new C5768b(this, 8));
        if (bundle != null) {
            this.f18365p0 = bundle.getBoolean("SHOW_TUTORIAL_SCROLL_NAVIGATION");
            this.f18364o0 = bundle.getBoolean("DIALOG_SHOWN");
        }
        TopLevelStore f1 = m12131f1();
        FragmentManager K0 = m11131K0();
        MutabilityOwnership.m3746l(K0, "supportFragmentManager");
        TopLevelStoreExtension.m1380a(f1, this, K0, this, this, (LegacyNavigation) this.f18362m0.getValue());
        int i = -1;
        Toolbar.C0375e eVar = new Toolbar.C0375e(-2, -1);
        eVar.f12463a = 8388613;
        ToolbarMenuView q0Var = new ToolbarMenuView(this);
        q0Var.setSelectedItem(0);
        ActivityHomeBinding jVar2 = this.f18363n0;
        if (jVar2 != null) {
            jVar2.f21708u.addView(q0Var, eVar);
            ActivityHomeBinding jVar3 = this.f18363n0;
            if (jVar3 != null) {
                jVar3.f21707t.setOnSelectSegmentListener(new C7296l(this, 4));
                ActivityHomeBinding jVar4 = this.f18363n0;
                if (jVar4 != null) {
                    jVar4.f21707t.m4467a(getResources().getStringArray(R.array.illust_manga_novel), ((WorkTypeRepository) this.f18360k0.getValue()).m6286c());
                    if (getIntent().hasExtra("REQUEST_TUTORIAL") && !this.f18364o0) {
                        this.f18364o0 = true;
                        CharcoalDialogFragment.C1197a aVar = CharcoalDialogFragment.f5632a;
                        String string = getString(R.string.confirm_learning_dialog_title);
                        MutabilityOwnership.m3746l(string, "getString(jp.pxv.android…rm_learning_dialog_title)");
                        String string2 = getString(R.string.confirm_learning_dialog_message);
                        String string3 = getString(R.string.confirm_learning_dialog_ok);
                        MutabilityOwnership.m3746l(string3, "getString(jp.pxv.android…nfirm_learning_dialog_ok)");
                        aVar.m9675a(string, string2, new CharcoalDialogButtonSettings.C1194a(string3, ConfirmLearningDialogEvent.ShowTutorialScrollNavigation.INSTANCE), true).show(m11131K0(), "confirm_learning_dialog");
                    } else if (getIntent().hasExtra("WORK_TYPE")) {
                        WorkType workType = (WorkType) getIntent().getSerializableExtra("WORK_TYPE");
                        if (workType != null) {
                            i = C4007b.f18366a[workType.ordinal()];
                        }
                        if (i == 1) {
                            ActivityHomeBinding jVar5 = this.f18363n0;
                            if (jVar5 != null) {
                                jVar5.f21707t.setSelectedSegment(1);
                            } else {
                                MutabilityOwnership.m3737u("binding");
                                throw null;
                            }
                        } else if (i == 2) {
                            ActivityHomeBinding jVar6 = this.f18363n0;
                            if (jVar6 != null) {
                                jVar6.f21707t.setSelectedSegment(2);
                            } else {
                                MutabilityOwnership.m3737u("binding");
                                throw null;
                            }
                        }
                        String string4 = getString(R.string.tutorial_confirm_scroll);
                        MutabilityOwnership.m3746l(string4, "getString(jp.pxv.android….tutorial_confirm_scroll)");
                        m4825h1(string4);
                    }
                    m4826g1().m12120h(StartUpScreen.HOME);
                    m12132e1().m4555e();
                    return;
                }
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
        MutabilityOwnership.m3737u("binding");
        throw null;
    }

    @Subscribe
    public final void onEvent(HomeRecyclerViewFirstScrolledEvent homeRecyclerViewFirstScrolledEvent) {
        ActivityHomeBinding jVar = this.f18363n0;
        if (jVar != null) {
            if (jVar.f21709v.getVisibility() == 0) {
                ActivityHomeBinding jVar2 = this.f18363n0;
                if (jVar2 != null) {
                    TutorialScrollNavigationView tutorialScrollNavigationView = jVar2.f21709v;
                    if (tutorialScrollNavigationView.getVisibility() == 0 && !tutorialScrollNavigationView.f19704c.isRunning()) {
                        tutorialScrollNavigationView.f19703b.cancel();
                        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(tutorialScrollNavigationView, "alpha", 0.0f);
                        tutorialScrollNavigationView.f19704c = ofFloat;
                        ofFloat.setDuration(300L);
                        tutorialScrollNavigationView.f19704c.addListener(new C5413s0(tutorialScrollNavigationView));
                        tutorialScrollNavigationView.f19704c.start();
                    }
                } else {
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
            }
            if (((LikeSettings) this.f18359j0.getValue()).m1117b()) {
                PixivSettings g1 = m4826g1();
                if (!g1.f734a.getBoolean(g1.f735b, false)) {
                    m4826g1().m12119i(true);
                    ActivityHomeBinding jVar3 = this.f18363n0;
                    if (jVar3 != null) {
                        jVar3.f21705r.setVisibility(0);
                        ActivityHomeBinding jVar4 = this.f18363n0;
                        if (jVar4 != null) {
                            TextView textView = jVar4.f21705r;
                            String string = getString(R.string.nav_more_like);
                            MutabilityOwnership.m3746l(string, "getString(jp.pxv.android…y.R.string.nav_more_like)");
                            Object obj = ContextCompat.f19963a;
                            Drawable b = ContextCompat.C4472c.m4259b(this, R.drawable.ic_like_inner_text);
                            EdgeTreatment.m3909i(b);
                            MutabilityOwnership.m3747j(b);
                            b.setBounds(0, 0, b.getIntrinsicWidth(), b.getIntrinsicHeight());
                            StringUtils bVar = new StringUtils(b);
                            SpannableString spannableString = new SpannableString(string);
                            int J = C5859m.m2737J(string, "(like)", 0, false, 6);
                            int i = J + 6;
                            if (J >= 0) {
                                spannableString.setSpan(bVar, J, i, 17);
                            }
                            textView.setText(spannableString);
                            ActivityHomeBinding jVar5 = this.f18363n0;
                            if (jVar5 != null) {
                                jVar5.f21705r.postDelayed(new RunnableC0624k(this, 4), 3000);
                            } else {
                                MutabilityOwnership.m3737u("binding");
                                throw null;
                            }
                        } else {
                            MutabilityOwnership.m3737u("binding");
                            throw null;
                        }
                    } else {
                        MutabilityOwnership.m3737u("binding");
                        throw null;
                    }
                }
            }
        } else {
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, p014ae.AdActivity, p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onPause() {
        ActivityHomeBinding jVar = this.f18363n0;
        if (jVar != null) {
            jVar.f21709v.setVisibility(8);
            ActivityHomeBinding jVar2 = this.f18363n0;
            if (jVar2 != null) {
                jVar2.f21710w.setVisibility(8);
                if (((LikeSettings) this.f18359j0.getValue()).m1117b()) {
                    PixivSettings g1 = m4826g1();
                    if (!g1.f734a.getBoolean(g1.f735b, false)) {
                        m4826g1().m12119i(true);
                    }
                }
                super.onPause();
                return;
            }
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
        MutabilityOwnership.m3737u("binding");
        throw null;
    }

    @Override // androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onSaveInstanceState(Bundle bundle) {
        MutabilityOwnership.m3745m(bundle, "outState");
        bundle.putBoolean("DIALOG_SHOWN", this.f18364o0);
        bundle.putBoolean("SHOW_TUTORIAL_SCROLL_NAVIGATION", this.f18365p0);
        super.onSaveInstanceState(bundle);
    }
}
